package org.anti996.lms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.anti996.lms.model.Driver;
import org.anti996.lms.mapper.DriverMapper;
import org.anti996.lms.model.Transport;
import org.anti996.lms.model.Warehouse;
import org.anti996.lms.service.DriverService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 司机表 服务实现类
 * </p>
 *
 * @author The Anti996 Authors
 * @since 2022-07-15
 */
@Service
public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements DriverService {
    @Override//根据司机用户名返回ID
   public  Driver getIdbyUsername(String username){
        QueryWrapper<Driver> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return  baseMapper.selectOne(wrapper);
    }
    @Override//司机登录
    public boolean login(String username, String password){
        QueryWrapper<Driver> wrapper=new QueryWrapper<>();
        wrapper.eq("username",username);
        wrapper.eq("password",password);
        return baseMapper.exists(wrapper);
    }

    @Override//根据收发仓库获取可用司机
    public Driver getdIdBywId(Integer wId) {
        QueryWrapper<Driver> wrapper = new QueryWrapper<>();
        wrapper.eq("state",0);
        wrapper.eq("w_id",wId);
        List<Driver> drivers=baseMapper.selectList(wrapper);
        Driver driver=drivers.get(0);
        driver.setState(1);
        return driver;
    }

    @Override//根据收发仓库判断是否有可用司机
    public boolean isexist(Integer widfrom){
        QueryWrapper<Driver> wrapper = new QueryWrapper<>();
        wrapper.eq("state",0);
        wrapper.eq("w_id",widfrom);
        return baseMapper.exists(wrapper);
    }

}
